/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admin.informe;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import DBMS.DataBaseManager;
import admin.permisos.PermisosManager;
import clases.Informe;
import java.util.ArrayList;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

/**
 *
 * @author carlo
 */


public class EliminarInforme extends DispatchAction {

    
    private final static String SUCCESS = "success";
    private final static String FAILURE = "failure";
    private static final String name = "Eliminar Informe";

    
    public ActionForward init(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        
        DataBaseManager dbms = DataBaseManager.getInstance();

        ArrayList<Informe> valores;
        Informe informeASerEliminado = (Informe) form;
        //valores = dbm.consultarRecordatorios(recordatorioASerEliminado);
        //recordatorioASerEliminado= valores<0>;
        System.out.println(informeASerEliminado.getIdinforme() + " I ");
        if (dbms.eliminarInforme(informeASerEliminado)) {
            informeASerEliminado.setMensajeOK("Recordatorio eliminado con exito");
            request.setAttribute("informe", informeASerEliminado);
            valores = dbms.consultarInformes(new Informe());
            request.setAttribute("informes", valores);
            return mapping.findForward(SUCCESS);
        } else {
            informeASerEliminado.setMensaje("No se puedo eliminar el"
                    + "informe.");
            request.setAttribute("informe", informeASerEliminado);

            valores = dbms.consultarInformes(new Informe());
            request.setAttribute("informes", valores);
            return mapping.findForward(FAILURE);
        }
    }

    /*
    public ActionForward populate(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    
    return mapping.findForward(SUCCESS);
    }
     */
}
